/**
* kaspersky virtual hall
* Author: Feil.Wang
* Date: 2013.07 
*/
var iframesrc='';
(function($) {
	$.dk_lightbox = function(object, options) {
		
		options = $.extend({},options);
		var jqobj = $(object);
		var jqobjWidth = jqobj.outerWidth();
		var jqobjHeight = jqobj.outerHeight();
		var ie6		= ($.browser.msie && $.browser.version < 7);
		var bbody	= $(document.body);
		var bwindow	= $(window);
		var bdocument	= $(document);

		//if(ie6){
				$('select').css('visibility','hidden');
		//}
		
		if(options.opacity){
			if($('#dk_lightboxfade')){
			$('#dk_lightboxfade').remove();
			}
			bojbfade = $("<div class=\"dk_lightboxfade\" id=\"dk_lightboxfade\"></div>").appendTo(bbody);
		}

		var ie6scroll = function(){
			jqobj.css({top:bwindow.scrollTop()+(bwindow.height() - jqobj.outerHeight())/2});
		};
		
		var positionLightBox = function(){
			jqobj.css({
				position: (ie6) ? "absolute" : "fixed",
				top: (ie6) ? (bwindow.height() - jqobjHeight)/2+bwindow.scrollTop() : (bwindow.height() - jqobjHeight)/2,
				left: "50%",
				zIndex:"3280",
				marginLeft: (jqobjWidth/2)*-1
			});
			if(options.opacity){
				bojbfade.css({
					position: "absolute",
					zIndex: 3270,
					height: bbody.height(),
					width: "100%",
					background: (options.background) ? options.background : "#000000",
					opacity: options.opacity,
					top: 0,
					left: 0,
					right: 0,
					bottom: 0
				});
			}
		};

		var removePrompt = function(){
			if(options.opacity){bojbfade.hide();}
			//if($('#dk_lightboxfade').css('display')!='none'){
				$('#dk_lightboxfade').remove();
			//}
			jqobj.hide();
			if(ie6) {bbody.unbind('scroll',ie6scroll);}
			bwindow.unbind('resize',positionLightBox);
			jqobj.fadeOut('fast',function(){
				$('select').css('visibility','visible');
			});
			
		};
		
		positionLightBox();
		
		if(ie6) {
			bwindow.scroll(ie6scroll);
		}
		bwindow.resize(positionLightBox);
	
		if(options.closed){
			jqobj.find(options.closed).click(function(){removePrompt()});
		}
		
		if(options.closedtime){
			setTimeout(removePrompt,options.closedtime);
		}
		
		if(options.closedobj){
			$(options.closedobj).click(function(){removePrompt()});
		}
		jqobj.show();
	};
})($);
var mainAnimate = {
	init : function(){
		var $main = $("#main");
		var $popBox = $(".pop-box");
		$main.animate({
			"left" : 0
		});
		setTimeout(function(){
			$popBox.animate({
				"width" : 670,
				"height" : 430,
				"left" : 155,
				"top" : 30
			},200)
			.animate({
				"width" : 600,
				"height" : 360,
				"left" : 190,
				"top" : 70
			},200)
			.animate({
				"width" : 620,
				"height" : 380,
				"left" : 180,
				"top" : 60
			},200);

		},250);
		
	}
}

var sweetTips = {
	init : function(target){
		var $tips = $("#tips");
		var boxPosX,boxPosY,sl,st;
		$(target).mouseenter(function(e){
			var $target = $(this);
			var val = $target.attr("tips-data");
			boxPosX = $(".container").offset().left;
			boxPosY = $(".container").offset().top;
			sl = $(document.body).scrollLeft();
			st = $(document.body).scrollTop();
			$tips.find("span").text(val);
			$tips.show();
			$tips.css({
				left : e.pageX - boxPosX - $tips.outerWidth()/2 - sl - 7 + "px",
				top : e.pageY - boxPosY - st - 60 + "px"
			});
		}).mousemove(function(e){
			$tips.css({
				left : e.pageX - boxPosX - $tips.outerWidth()/2 - sl - 7 + "px",
				top : e.pageY - boxPosY - st - 60 + "px"
			});
		}).mouseleave(function(){
			$tips.hide();
		});
	}
}

var vcardPreview = function(target){
	var $vcardBox = $(target).closest(".jDialog-container").find(".i-user-info");
	var boxPosY
	$(target).live({
		mouseenter : function(){
			var _this = $(this),
				imgSrc = _this.attr("data-avatar"),
				name = _this.attr("data-name"),
				corp = _this.attr("data-corp"),
				post = _this.attr("data-post");
			boxPosY = $(".container").offset().top;
			$vcardBox.find(".u_avatar").attr("src",imgSrc);
			$vcardBox.find(".u_name").text(name);
			$vcardBox.find(".u_corp").text(corp);
			$vcardBox.find(".u_post").text(post);
			$vcardBox.show();
		},
		mousemove : function(e){
			$vcardBox.css({
				top : e.pageY - boxPosY - 135 + "px"
			});
		},
		mouseleave : function(){
			$vcardBox.hide();
		}
	});
}
//自定义滚动条
function scrollBar(obj){
	var pane = $(obj);
	if(pane.length!==0){
		pane.jScrollPane({
			verticalDragMinHeight: 69,
			verticalDragMaxHeight: 69,
			mouseWheelSpeed: 10
		});
	}
}

function tabs(tab,target){
	var $tabsObj = $(tab);
	var $target = $(target);
	$tabsObj.live("click",function(){
		var _this = $(this);
		var index = _this.index();
		_this.addClass("current").siblings().removeClass("current");
		$target.eq(index).show(0,function(){
			scrollBar(".table-container");
			scrollBar("#pRightBlock");
		}).siblings().hide();
	});

}
$(function(){
	
	mainAnimate.init();
	
	sweetTips.init(".shortcut,.nav-exit,.link a,.mini-nav-list a,.product-item");
	
	$.jDialog.init();
	
	if($("#picSlider").length!==0){
		$("#picSlider").slidesjs({
			width: 150,
			height: 160,
			play: {
				effect : "fade",
				interval: 3000,
				auto: true
			},
			effect: {
				fade: {
					speed: 800
				}
			}
		});
	}
	
	$("#navSwitch").click(function(){
		var _this = $(this);
		var $navBar = _this.parent();
		if( !_this.hasClass("arrow-open")){
			$navBar.animate({
				"right" : 0
			},200,function(){
				_this.addClass("arrow-open");
			});
		}else{
			$navBar.animate({
				"right" : -300
			},200,function(){
				_this.removeClass("arrow-open");
			});
		}
	});
	tabs("#tabs li","#boxMain .block-item");
	tabs("#pMenu li","#pRight .p-right-block");
	
	scrollBar(".table-container");
	
	$(".i-user-list a").live("click",function(){
		var _this = $(this),
			name = _this.attr("data-name"),
			corp = _this.attr("data-corp"),
			post = _this.attr("data-post");
		$.jDialog.load({
			id:"vcardInfo",
			title:"个人信息 - "+name,
			url:"i-vcard-info.html"
		})
	});
	
});


(function($){
		
	$.jDialog = {
		
		zIndex : 99,

		init : function(){
			if($(".jDialog-container").length==0)
			return;
			var _opts = this.opts;
			var thisBox = $(".jDialog-container");
			var closeBtn = thisBox.find(".j-btn-close");
			
			thisBox.draggable({
				containment: "#main",
				handle: ".j-title",
				cursor: "move",
				stack: ".jDialog-container"
			});
			closeBtn.click(function(){
				$('#v_frame').show();
				var thisBox = $(this).closest(".jDialog-container");
				var w = thisBox.width();
				var h = thisBox.height();
				thisBox.animate({
					width : 0,
					height: 0,
					left : 500,
					top : 285
				},300,function(){
					thisBox.css({
						width : w,
						height: h,
						display:"none"
					});
				});
				thisBox.removeClass("isOpen");
			});
		}, 
		
		open : function(obj,callback){
			$('#v_frame').hide();
			var obj = $(obj);
			var	w = obj.width();
			var	h = obj.height();
			if(!obj.hasClass("isOpen")){
				this.zIndex++;
				obj.css({
					width : 0,
					height: 0,
					left : 500,
					top : 285,
					display : 'block',
					zIndex : this.zIndex
				}).addClass("isOpen");
				obj.animate({
					width : w,
					height: h,
					left : 500-(w+20)/2,
					top : 285-(h+20)/2
				},300);
				obj.draggable({
					 stop: function( event, ui ) {
					 	$.jDialog.zIndex = obj.css("z-index");
					 }
				});
				if(!!callback){callback()}
			}
		},
		
		load : function(options,callback){
			$('#v_frame').hide();
			/* 定义初始变量 */
			var defaults = {
				id : '',
				title : '',
				url : ''
			};
   			var opts = $.extend(defaults, options);
			if($("[id='+opts.id+']").length!==0){
				return;
			}
			
			$("#main").append('<div id="'+ opts.id +'" class="jDialog-container">'
							 +'		<table>'
							 +'			<tr>'
							 +'				<td>'
							 +'					<div class="j-title">'+opts.title
							 +'						<a class="j-btn-close tran" href="javascript:;"></a>'
							 +'					</div>'
							 +'				</td>'
							 +'			</tr>'
							 +'			<tr>'
							 +'				<td class="box-cnt">'
							 +'				</td>'
							 +'			</tr>'
							 +'		</table>'
							 +'</div>');	
			var thisBox = $("#"+opts.id)
			var boxCnt = thisBox.find(".box-cnt");
			var closeBtn = thisBox.find(".j-btn-close");
			
			thisBox.draggable({
				containment: "#main",
				handle: ".j-title",
				cursor: "move",
				stack: ".jDialog-container",
				stop: function( event, ui ) {
					$.jDialog.zIndex = thisBox.css("z-index");
				 }
			});
			boxCnt.load(opts.url,function(responseTxt,statusTxt,xhr){
				if(statusTxt=="success"){
					var _zIndex = $.jDialog.zIndex;
					var w = thisBox.width();
					var h = thisBox.height();
					$.jDialog.zIndex++;
					thisBox.css({
						width : 0,
						height: 0,
						left : 500,
						top : 285,
						display : 'block',
						zIndex : _zIndex
					});
					thisBox.animate({
						width : w,
						height: h,
						left : 500-(w+20)/2,
						top : 285-(h+20)/2
					},300);
					if(!!callback){callback()}
				}else if(statusTxt=="error"){
					alert("加载失败");
				}
			});		

			closeBtn.live("click",function(){
				$('#v_frame').show();
				thisBox.animate({
					width : 0,
					height: 0,
					left : 500,
					top : 285
				},300,function(){
					thisBox.remove();
				});
			});
			
		},
		
		/* iframe中关闭dialog */
		close : function(obj){
			$('#v_frame').show();
			var thisBox = window.parent.$(obj);
			var w = thisBox.width();
			var h = thisBox.height();
			thisBox.animate({
				width : 0,
				height: 0,
				left : 500,
				top : 285
			},300,function(){
				thisBox.remove();
			});
		}
	}
	
})(jQuery);



//打开展位列表
function openBoothList(){
	$.jDialog.open("#boothList")
}
//打开留言
function openLeaveMsg(){
	$.jDialog.open("#leaveMsg");
}

//打开产品介绍
function openProductIntro(idx){
	$.jDialog.open("#productIntro",function(){
		$("#pMenu li").eq(idx).addClass("current").siblings().removeClass("current");
		$("#pRight .p-right-block").eq(idx).show().siblings().hide();
		scrollBar("#pRightBlock");		
		
		$(".p-img-tabs li").click(function(){
			var index = $(this).index();
			$(this).addClass("current").siblings().removeClass("current");
			$(".p-img-container").children().eq(index).show().siblings().hide();
		});
	});
}
//打开在线用户
function openUserList(){
	$.jDialog.load({
		id:"userList",
		title:"谁在这里？(10)",
		url:"i-user-list.html"
	},function(){
		scrollBar(".i-user-list-wrap");
		vcardPreview(".i-user-list a");
	})
}
//打开我的资料
function openMyProfile(){
	$.jDialog.load({
		id:"myProfile",
		title:"我的资料",
		url:"i-my-profile.html"
	},function(){
		tabs(".profile-tabs li","#profileMain .profile-block");
	})
}
//打开名片盒
function openVcardBox(){
	$.jDialog.load({
		id:"vcardBox",
		title:"名片盒",
		url:"i-vcard-box.html"
	},function(){
		scrollBar(".i-vcard-box");
		vcardPreview(".i-vcard-list a");
	})
}

//退出
function exitDialog(){
	$.jDialog.open("#exitDialog");
}

//搜索提示
function searchSubmit(){
	$(".search-result").fadeIn(300,function(){
		setTimeout(function(){
			$(".search-result").fadeOut(300);
		},1000);
	});
}